/*!
 * jQuery Cookie Plugin v1.4.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2013 Klaus Hartl
 * Released under the MIT license
 */
define(function(require, exports, module) {
	require('jquery');
	(function (factory) {
		if (typeof define === 'function' && define.amd) {
			// AMD
			define(['jquery'], factory);
		} else if (typeof exports === 'object') {
			// CommonJS
			factory(require('jquery'));
		} else {
			// Browser globals
			factory(jQuery);
		}
	}(function () {

		var pluses = /\+/g;

		function encode(s) {
			return config.raw ? s : encodeURIComponent(s);
		}

		function decode(s) {
			return config.raw ? s : decodeURIComponent(s);
		}

		function stringifyCookieValue(value) {
			return encode(config.json ? JSON.stringify(value) : String(value));
		}

		function parseCookieValue(s) {
			if (s.indexOf('"') === 0) {
				// This is a quoted cookie as according to RFC2068, unescape...
				s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
			}

			try {
				// Replace server-side written pluses with spaces.
				// If we can't decode the cookie, ignore it, it's unusable.
				// If we can't parse the cookie, ignore it, it's unusable.
				s = decodeURIComponent(s.replace(pluses, ' '));
				return config.json ? JSON.parse(s) : s;
			} catch(e) {}
		}

		function read(s, converter) {
			var value = config.raw ? s : parseCookieValue(s);
			return $.isFunction(converter) ? converter(value) : value;
		}
		var config = $.cookie = function (key, value, options) {

			// Write

			if (value !== undefined && !$.isFunction(value)) {
				options = $.extend({}, config.defaults, options);

				if (typeof options.expires === 'number') {
					var days = options.expires, t = options.expires = new Date();
					t.setTime(+t + days * 864e+5);
				}

				return (document.cookie = [
					encode(key), '=', stringifyCookieValue(value),
					options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
					options.path	? '; path=' + options.path : '',
					options.domain  ? '; domain=' + options.domain : '',
					options.secure  ? '; secure' : ''
				].join(''));
			}

			// Read

			var result = key ? undefined : {};

			// To prevent the for loop in the first place assign an empty array
			// in case there are no cookies at all. Also prevents odd result when
			// calling $.cookie().
			var cookies = document.cookie ? document.cookie.split('; ') : [];

			for (var i = 0, l = cookies.length; i < l; i++) {
				var parts = cookies[i].split('=');
				var name = decode(parts.shift());
				var cookie = parts.join('=');

				if (key && key === name) {
					// If second argument (value) is a function it's a converter...
					result = read(cookie, value);
					break;
				}

				// Prevent storing a cookie that we couldn't decode.
				if (!key && (cookie = read(cookie)) !== undefined) {
					result[name] = cookie;
				}
			}

			return result;
		};

		config.defaults = {};

		$.removeCookie = function (key, options) {
			if ($.cookie(key) === undefined) {
				return false;
			}

			// Must not alter options, thus extending a fresh object...
			$.cookie(key, '', $.extend({}, options, { expires: -1 }));
			return !$.cookie(key);
		};

	}));

	// module.exports = {
	// 	userArea: $('.userAreaW'),
	// 	carName: '',
	// 	carNameCN: '',
	// 	userID: '',
	// 	userName: '',
	// 	userInfo: {},
	// 	carNameArr: ['octavia','superb','octavia-c','rapid','yeti','yeti2','yeti3','spaceback','fabia','fabia-sport','superb-d'],
	// 	carNameArrCN: ['明锐','速派','明锐经典款','昕锐','野帝越野版','野帝都会版','野帝原装进口','昕动','晶锐','晶锐sport','速尊原装进口'],
	// 	queryString: function(str){
	// 		var sValue=location.search.match(new RegExp("[\?\&]"+str+"=([^\&]*)(\&?)","i"));
	// 		return sValue?sValue[1]:sValue;
	// 	},
	// 	setUserArea: function(){
	// 		this.login = this.userArea.find('.login');
	// 		this.register = this.userArea.find('.register');
	// 		this.login.on('click',function(){
	// 			$.loginSkoda({memsrc:2,redirecturl:location.href});
	// 		});
	// 		this.register.on('click',function(){
	// 			$.registSkoda({memsrc:2,redirecturl:location.href});
	// 		});
	// 	},
	// 	setCarName: function(){
 //            var hrefArr = location.href.split(/\//g);
 //            if(this.queryString('cartype')){
 //                hrefArr = [this.queryString('cartype')];
 //            }
 //            for(var i=0; i< hrefArr.length; i++){
 //                if($.inArray(hrefArr[i], this.carNameArr)>=0){
 //                    this.carName = hrefArr[i];
 //                    this.carNameCN = this.carNameArrCN[$.inArray(hrefArr[i], this.carNameArr)];
 //                    $.cookie('_loc_carName', this.carName, { expires: 7, path: '/' });
 //                    $.cookie('_loc_carNameCN', this.carNameCN, { expires: 7, path: '/' });
 //                    if(this.loginBL){
 //                        $.ajax({
 //                            url:'/api/interest/post/'+this.carName+'/'+this.userInfo.UID,
 //                            type:'GET',
 //                            dataType:'json',
 //                            success: function(data){
 //                                //console.log(data)
 //                            }
 //                        });
 //                    }
 //                };
 //            };
 //        },
	// 	setUserInfo: function(){
	// 		this.loginBL = $.checkLogin ? $.checkLogin() : false;
	// 		var s = ''
	// 			sf = this;
	// 		if(this.loginBL){
	// 			this.userInfo = $.getUID();
	// 			for(var i in this.userInfo){
	// 				s += this.userInfo[i]+'|';
	// 			};
	// 			s = s.replace(/\|$/,'');
	// 			this.userArea.each(function(){
	// 				$(this).html('');
	// 				var li = $('<div class="user_name"><span><a href="http://www.skoda.com.cn/myprofile">'+sf.userInfo.UserName+'</a></span></div><div class="logout"><span>登出</span></div>');
	// 				li.appendTo(this);
	// 			});
				
	// 			this.userArea.find('.logout').on('click',function(){
	// 				$.logOut({memsrc:2,redirecturl:location.href});
	// 			});
	// 		};
	// 		$.cookie('_loc_userInfo', s, { expires: 7, path: '/' });
	// 	},
	// 	getCarName: function(){
	// 		var sf = this;
	// 		this.carName = $.cookie('_loc_carName');
	// 		if($.cookie('_loc_userInfo')){
	// 			$.ajax({
	// 				url:'/api/interest/get/'+this.userInfo.UID,
	// 				type:'GET',
	// 				async: false,
	// 				dataType:'json',
	// 				cache: false,
	// 				success: function(data){
	// 					sf.carName = data.interest;
	// 				}
	// 			});
	// 		};
	// 		return this.carName;
	// 	},
	// 	getCarNameCN: function(){
	// 		this.carNameCN = $.cookie('_loc_carNameCN');
	// 		return this.carNameCN;
	// 	},
	// 	help_trigger: function(){
	// 		window.help_bl = true;
	// 		$('.help_trigger').each(function(){
	// 			$(this).click(function(){
	// 				$(this).find('span').each(function(index,item){
	// 					if($(item).hasClass('active')){
	// 						$(item).removeClass('active');
	// 					}else{
	// 						if(index===0){
	// 							window.help_bl = true;
	// 						}else{
	// 							window.help_bl = false;
	// 						}
	// 						$(item).addClass('active');
	// 					}
	// 				});
	// 				//console.log(window.help_bl)
	// 			});
	// 		});
	// 	},
	// 	init: function(){
	// 		this.setUserInfo();
	// 		this.setCarName();
	// 		this.setUserArea();
	// 		this.help_trigger();
	// 	}
	// };
});
